<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<html>
  <head>
    <title>登陆处理页面</title>
  </head>
  <body>
<%
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String referer = request.getHeader("Referer");
if(referer==null||referer.trim().length()==0){
response.sendRedirect("index.jsp");
return;
}
String name=request.getParameter("username");
String pwd=request.getParameter("password");
%>
<%!
String url = "jdbc:mysql://127.0.0.1:3306/newsdb?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8";
String username = "root";
String password = "123456";
%>
<%
    Connection conn = DriverManager.getConnection(url,username,password);//得到连接
    PreparedStatement pstmt = conn.prepareStatement("select username,password from tb_user where username=? AND password = ?");
    pstmt.setString(1,name);
    pstmt.setString(2,pwd);
    ResultSet rs = pstmt.executeQuery();
    if(rs.next()) {
        if(name.trim().equals("admin")&&pwd.trim().equals("admin"))
        response.sendRedirect("./adminstrator/index.html");
        else{
            session.setAttribute("uName", name);
            response.sendRedirect("index2.jsp");
        }
    }
        else{
            session.setAttribute("usertxt", "用户名或密码错误！！！");
            response.sendRedirect("loginRegister.jsp");
    }

//判断登陆界面的用户名和密码，根据输入的不同情况进行不同的处理
%>
</body>

</html>

